﻿using System;
using System.Collections.Generic;
using System.Text;
using Abp.Dependency;
using Abp.Events.Bus.Entities;
using Abp.Events.Bus.Handlers;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.BrandInfo.Dto;
using FwProject.Comm;
using FwProject.Core.AppVersion;
using FwProject.ShoppingMall.BrandInfo;

namespace FwProject.EventHandle
{
    public class BrandHandle : IEventHandler<EntityChangedEventData<Brand>>, ITransientDependency
    {
        public readonly ICacheManager _catchmanager;
        public IRemoteEventBus remoteEventBus { get; set; }//缓存对象
        public BrandHandle(ICacheManager catchmanager)
        {
            _catchmanager = catchmanager;
            remoteEventBus = NullRemoteEventBus.Instance;
        }
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void HandleEvent(EntityChangedEventData<Brand> eventData)
        {
            ICache cache = _catchmanager.GetCache(nameof(Brand));
            cache.Remove("list");

            var catcheventDate = new RemoteEventData(RemoteTypeHelp.TYPESEARCH)
            {
                Data = { [RemoteTypeHelp.MODELID] = eventData.Entity.Id ,[RemoteTypeHelp.MODELNAME] =nameof(BrandDto) }
            };
            remoteEventBus.Publish(RemoteTypeHelp.TOPICAPPSYSTEMSEARCH, catcheventDate);
        }
    }
}
